package com.platform.config;

import com.fcjs.cache.core.DefaultCache;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhangyaohai
 * @create 2018-08-02 15:53
 **/
@Configuration
public class CommonConfig {

    @Value("${cc-fcjs.redis.host}")
    private String host;

    @Value("${cc-fcjs.redis.serviceName}")
    private String serviceName;

    @Value("${cc-fcjs.redis.port}")
    private int port;

    @Value("${cc-fcjs.redis.password}")
    private String password;

    @Value("${cc-fcjs.redis.timeout}")
    private int timeout;

    @Bean
    public Gson gson() {
        return new GsonBuilder()
                .setVersion(1.0)
                .disableInnerClassSerialization()
                .setFieldNamingPolicy(FieldNamingPolicy.IDENTITY)
                .setDateFormat("yyyy-MM-dd")
                .create();
    }

    @Bean
    public DefaultCache defaultCache() {
        return new DefaultCache( host,  serviceName,  port,  password, timeout);
    }


}
